<?php

if (!function_exists('validateApplicationFormData')) {

    function validateApplicationFormData($awardInfo, $formData)
    {
        if (empty($formData)) {
            return '申报书内容为空';
        }
        if ($awardInfo['id'] == 1) {
            return validateApplicationFormDataAward1($formData);
        } elseif ($awardInfo['id'] == 2) {
            return validateApplicationFormDataAward2($formData);
        }
        return null;
    }

    function validateApplicationFormDataAward1($formData)
    {
        if (empty($formData->basic_situation)) {
            return '请填写基本情况';
        }

        $basic_situation = $formData->basic_situation;
        if (empty($basic_situation->declare_company)) {
            return '请填写牵头申报单位';
        } else if (empty($basic_situation->project_name)) {
            return '请填写项目名称';
        } else if (empty($basic_situation->complete_people)) {
            return '请填写主要完成人';
        } else if (empty($basic_situation->complete_companies)) {
            return '请填写主要完成单位';
        } else if (empty($basic_situation->invention) && $basic_situation->invention != 0) {
            return '请填写授权发明专利数量';
        } else if (empty($basic_situation->other_invention) && $basic_situation->other_invention != 0) {
            return '请填写授权的其他知识产权数量';
        } else if (empty($basic_situation->develop_domain)) {
            return '请选择国家重点发展领域';
        } else if (empty($basic_situation->task_origin)) {
            return '请选择任务来源';
        } else if (empty($basic_situation->project_dateRange)) {
            return '请填写项目的起止时间';
        } else if (empty($basic_situation->plans)) {
            return '请填写具体计划、基金的名称和编号';
        } else if (empty($basic_situation->technical)) {
            return '请填写已呈交科技报告编号';
        } else if (empty($basic_situation->scientific_evaluation_institutions)) {
            return '请填写科技成果评价机构';
        } else if (empty($basic_situation->scientific_evaluation_level)) {
            return '请填写科技成果评价水平';
        }

        if (empty($formData->scientific)) {
            return '请填写科技成果简介';
        }
        if (empty($formData->innovate)) {
            return '请填写主要科技创新';
        }
        if (empty($formData->evaluate)) {
            return '请填写客观评价';
        }

        if (empty($formData->generalize)) {
            return '请填写推广应用情况、经济效益和社会效益';
        }

        $generalize = $formData->generalize;
        if (empty($generalize->situation)) {
            return '请填写推广应用情况';
        }

        if (empty($generalize->economic_benefit)) {
            return '请添加推广应用近两年的经济效益';
        } else {
            $economicBenefit = $generalize->economic_benefit;
            foreach ($economicBenefit as $economicKey => $economicValue) {
                $showIndex = $economicKey + 1;
                if (empty($economicValue->year)) {
                    return "请填写推广应用近两年的经济效益第{$showIndex}条的自然年";
                } elseif (!isset($economicValue->finish_sale)) {
                    return "请填写推广应用近两年的经济效益第{$showIndex}条的完成单位新增销售额";
                } elseif (!isset($economicValue->finish_profit)) {
                    return "请填写推广应用近两年的经济效益第{$showIndex}条的完成单位新增利润";
                } elseif (!isset($economicValue->other_sale)) {
                    return "请填写推广应用近两年的经济效益第{$showIndex}条的其他应用单位新增销售额";
                } elseif (!isset($economicValue->other_profit)) {
                    return "请填写推广应用近两年的经济效益第{$showIndex}条的其他应用单位新增利润";
                }
            }
        }

        if (empty($generalize->description)) {
            return '请填写推广应用的经济效益指标说明';
        } else if (empty($generalize->other_description)) {
            return '请填写推广应用的其他经济效益指标说明';
        } else if (empty($generalize->society_benefit)) {
            return '请填写推广应用的社会效益';
        }

        if (empty($formData->knowledge_property)) {
            return '请添加主要知识产权证明目录';
        } else {
            $knowledgeProperty = $formData->knowledge_property;
            foreach ($knowledgeProperty as $knowledgeKey => $knowledgeValue) {
                $showIndex = $knowledgeKey + 1;
                if (empty($knowledgeValue->type)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的知识产权类别";
                } elseif (empty($knowledgeValue->name)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的知识产权具体名称";
                } elseif (empty($knowledgeValue->country)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的国家(地区)";
                } elseif (empty($knowledgeValue->authorization_num)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的授权号";
                } elseif (empty($knowledgeValue->authorization_date)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的授权日期";
                } elseif (empty($knowledgeValue->certificate_number)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的证书编号";
                } elseif (empty($knowledgeValue->obligee)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的权利人";
                } elseif (empty($knowledgeValue->inventor)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的发明人";
                } elseif (empty($knowledgeValue->status)) {
                    return "请填写主要知识产权证明目录第{$showIndex}条的发明专利有效状态";
                }
            }
        }
        if (empty($formData->finish_people)) {
            return '请添加主要完成人';
        } else {
            $finishPeopleList = $formData->finish_people;
            foreach ($finishPeopleList as $finishPeopleKey => $finish_people) {
                $showIndex = $finishPeopleKey + 1;
                if (empty($finish_people->name)) {
                    return '请填写第'.$showIndex.'个主要完成人员姓名';
                } else if (empty($finish_people->rank)) {
                    return '请填写第'.$showIndex.'个主要完成人员排名';
                } else if (empty($finish_people->nationality)) {
                    return '请填写第'.$showIndex.'个主要完成人员国籍';
                } else if (empty($finish_people->birth)) {
                    return '请填写第'.$showIndex.'个主要完成人员出生日期';
                } else if (empty($finish_people->birth_place)) {
                    return '请填写第'.$showIndex.'个主要完成人员出生地';
                } else if (empty($finish_people->nation)) {
                    return '请填写第'.$showIndex.'个主要完成人员民族';
                } else if (empty($finish_people->id_card)) {
                    return '请填写第'.$showIndex.'个主要完成人员身份证号';
                } else if (empty($finish_people->returnee)) {
                    return '请填写第'.$showIndex.'个主要完成人员是否归国人员';
                } else if ($finish_people->returnee == '是' && empty($finish_people->return_time)) {
                    return '请填写第'.$showIndex.'个主要完成人员归国时间';
                } else if (empty($finish_people->profession)) {
                    return '请填写第'.$showIndex.'个主要完成人员技术职称';
                } else if (empty($finish_people->education)) {
                    return '请填写第'.$showIndex.'个主要完成人员最高学历';
                } else if (empty($finish_people->degress)) {
                    return '请填写第'.$showIndex.'个主要完成人员最高学位';
                } else if (empty($finish_people->graduate_school)) {
                    return '请填写第'.$showIndex.'个主要完成人员毕业学校';
                } else if (empty($finish_people->graduate_time)) {
                    return '请填写第'.$showIndex.'个主要完成人员毕业时间';
                } else if (empty($finish_people->major)) {
                    return '请填写第'.$showIndex.'个主要完成人员所学专业';
                } else if (empty($finish_people->mail)) {
                    return '请填写第'.$showIndex.'个主要完成人员电子邮箱';
                } else if (empty($finish_people->phone)) {
                    return '请填写第'.$showIndex.'个主要完成人员办公电话';
                } else if (empty($finish_people->telephone)) {
                    return '请填写第'.$showIndex.'个主要完成人员移动电话';
                } else if (empty($finish_people->address)) {
                    return '请填写第'.$showIndex.'个主要完成人员通讯地址';
                } else if (empty($finish_people->post_code)) {
                    return '请填写第'.$showIndex.'个主要完成人员邮政编码';
                } else if (empty($finish_people->job)) {
                    return '请填写第'.$showIndex.'个主要完成人员行政职务';
                } else if (empty($finish_people->department)) {
                    return '请填写第'.$showIndex.'个主要完成人员二级单位';
                } else if (empty($finish_people->groups)) {
                    return '请填写第'.$showIndex.'个主要完成人员党派';
                } else if (empty($finish_people->project_range)) {
                    return '请填写第'.$showIndex.'个主要完成人员参加项目的起止时间';
                } else if (empty($finish_people->contribution)) {
                    return '请填写第'.$showIndex.'个主要完成人员对本项目技术创造性贡献';
                } else if (empty($finish_people->award_situation)) {
                    return '请填写第'.$showIndex.'个主要完成人员曾获国家（省部及社会力量）科技奖励情况';
                } else if (empty($finish_people->company)) {
                    return '请填写第'.$showIndex.'个主要完成人员工作单位';
                }
            }
        }

        if (empty($formData->finish_company)) {
            return '请添加主要完成单位';
        } else {
            $finishCompanyList = $formData->finish_company;
            foreach ($finishCompanyList as $finishCompanyKey => $finish_company) {
                $showIndex = $finishCompanyKey + 1;
                if (empty($finish_company->company_name)) {
                    return '请填写第'.$showIndex.'个主要完成单位单位名称';
                } else if (empty($finish_company->company_rank)) {
                    return '请填写第'.$showIndex.'个主要完成单位单位排名';
                } else if (empty($finish_company->legal_person)) {
                    return '请填写第'.$showIndex.'个主要完成单位法定代表人';
                } else if (empty($finish_company->location)) {
                    return '请填写第'.$showIndex.'个主要完成单位所在地';
                } else if (empty($finish_company->company_nature)) {
                    return '请填写第'.$showIndex.'个主要完成单位单位性质';
                } else if (empty($finish_company->company_fax)) {
                    return '请填写第'.$showIndex.'个主要完成单位传真';
                } else if (empty($finish_company->post_code)) {
                    return '请填写第'.$showIndex.'个主要完成单位邮政编码';
                } else if (empty($finish_company->company_address)) {
                    return '请填写第'.$showIndex.'个主要完成单位通讯地址';
                } else if (empty($finish_company->link_man)) {
                    return '请填写第'.$showIndex.'个主要完成单位联系人';
                } else if (empty($finish_company->company_tel)) {
                    return '请填写第'.$showIndex.'个主要完成单位单位电话';
                } else if (empty($finish_company->phone)) {
                    return '请填写第'.$showIndex.'个主要完成单位移动电话';
                } else if (empty($finish_company->email)) {
                    return '请填写第'.$showIndex.'个主要完成单位电子邮箱';
                } else if (empty($finish_company->contribution)) {
                    return '请填写第'.$showIndex.'个主要完成单位对本项目科技创新和推广应用情况的贡献';
                }
            }
        }

        if (empty($formData->attachments)) {
            return '请上传附件';
        }
        $attachments = $formData->attachments;
        if (empty($attachments->core_ip_certs)) {
            return '请上传附件中的核心知识产权证明';
        } else if (empty($attachments->evaluation_certs)) {
            return '请上传附件中的评价证明及国家法律法规要求审批的批准文件';
        } else if (empty($attachments->tech_reports)) {
            return '请上传附件中的科技查新报告';
        } else if (empty($attachments->application_certs)) {
            return '请上传附件中的应用证明';
        } else if (empty($attachments->coauthers)) {
            return '请上传附件中的完成人合作关系说明及情况汇总表';
        } else if (empty($attachments->others)) {
            return '请上传附件中的其他证明';
        }

        return null;
    }

    function validateApplicationFormDataAward2($formData)
    {
        if (empty($formData->basic)) {
            return '请填写基本信息';
        }
        $basic = $formData->basic;
        if (empty($basic->name)) {
            return '请填写姓名';
        } else if (empty($basic->document_photo)) {
            return '请上传证件照';
        } else if (empty($basic->nation)) {
            return '请填写民族';
        } else if (empty($basic->eduction)) {
            return '请填写学历';
        } else if (empty($basic->degree)) {
            return '请填写学位';
        } else if (empty($basic->groups)) {
            return '请填写党派';
        } else if (empty($basic->birth)) {
            return '请填写出生日期';
        } else if (empty($basic->graduate)) {
            return '请填写毕业时间';
        } else if (empty($basic->professional)) {
            return '请填写专业技术职务';
        } else if (empty($basic->duty)) {
            return '请填写行政职务';
        } else if (empty($basic->mail)) {
            return '请填写E-mail';
        } else if (empty($basic->phone)) {
            return '请填写手机号码';
        } else if (empty($basic->company)) {
            return '请填写工作单位全称';
        } else if (empty($basic->company_phone)) {
            return '请填写单位电话';
        } else if (empty($basic->company_address)) {
            return '请填写单位地址';
        } else if (empty($basic->company_email)) {
            return '请填写邮编';
        } else if (empty($basic->job)) {
            return '请填写社会职务';
        } else if (empty($basic->situation)) {
            return '请填写国内外学术组织任职情况';
        }
        if (empty($basic->resume)) {
            return '请添加本人简历';
        } else {
            $resumeList = $basic->resume;
            foreach ($resumeList as $resumeKey => $resumeValue) {
                $showIndex = $resumeKey + 1;
                if (empty($resumeValue->range)) {
                    return "请填写本人简历第{$showIndex}条的起止年月";
                } elseif (empty($resumeValue->address)) {
                    return "请填写本人简历第{$showIndex}条的所在学校";
                } elseif (empty($resumeValue->experience)) {
                    return "请填写本人简历第{$showIndex}条的职务(专业)";
                }
            }
        }

        if (empty($formData->award)) {
            return '请添加所获科技奖励和荣誉称号';
        } else {
            $awardList = $formData->award;
            foreach ($awardList as $awardKey => $awardValue) {
                $showIndex = $awardKey + 1;
                if (empty($awardValue->award_name)) {
                    return "请填写所获科技奖励和荣誉称号情况第{$showIndex}条的奖励或荣誉名称";
                } elseif (empty($awardValue->company_of_issue)) {
                    return "请填写所获科技奖励和荣誉称号情况第{$showIndex}条的授奖单位";
                } elseif (empty($awardValue->date)) {
                    return "请填写所获科技奖励和荣誉称号情况第{$showIndex}条的授奖日期";
                } elseif (empty($awardValue->total)) {
                    return "请填写所获科技奖励和荣誉称号情况第{$showIndex}条的获奖总人数";
                } elseif (empty($awardValue->rank)) {
                    return "请填写所获科技奖励和荣誉称号情况第{$showIndex}条的本人排名";
                }
            }
        }

        if (empty($formData->paper)) {
            return '请添加发表论文及专著';
        } else {
            $paperList = $formData->paper;
            foreach ($paperList as $paperKey => $paperValue) {
                $showIndex = $paperKey + 1;
                if (empty($paperValue->paper_name)) {
                    return "请填写发表论文及专著第{$showIndex}条的论文/著作名称";
                } elseif (empty($paperValue->date)) {
                    return "请填写发表论文及专著第{$showIndex}条的年份";
                } elseif (empty($paperValue->rank)) {
                    return "请填写发表论文及专著第{$showIndex}条的本人排名";
                } elseif (empty($paperValue->partner)) {
                    return "请填写发表论文及专著第{$showIndex}条的主要合作者";
                } elseif (empty($paperValue->publish)) {
                    return "请填写发表论文及专著第{$showIndex}条的发表刊物或出版社名称";
                } elseif (empty($paperValue->contribution)) {
                    return "请填写发表论文及专著第{$showIndex}条的本人作用或主要贡献";
                }
            }
        }

        if (empty($formData->property)) {
            return '请添加所获知识产权证书';
        } else {
            $knowledgeProperty = $formData->property;
            foreach ($knowledgeProperty as $knowledgeKey => $knowledgeValue) {
                $showIndex = $knowledgeKey + 1;
                if (empty($knowledgeValue->property_category)) {
                    return "请填写所获知识产权证书第{$showIndex}条的知识产权类别";
                } elseif (empty($knowledgeValue->item_name)) {
                    return "请填写所获知识产权证书第{$showIndex}条的授权项目名称";
                } elseif (empty($knowledgeValue->country)) {
                    return "请填写所获知识产权证书第{$showIndex}条的国家(地区)";
                } elseif (empty($knowledgeValue->authorization_num)) {
                    return "请填写所获知识产权证书第{$showIndex}条的授权号";
                } elseif (empty($knowledgeValue->authorization_date)) {
                    return "请填写所获知识产权证书第{$showIndex}条的授权日期";
                } elseif (empty($knowledgeValue->certificate_number)) {
                    return "请填写所获知识产权证书第{$showIndex}条的证书编号";
                } elseif (empty($knowledgeValue->obligee)) {
                    return "请填写所获知识产权证书第{$showIndex}条的权利人";
                } elseif (empty($knowledgeValue->inventor)) {
                    return "请填写所获知识产权证书第{$showIndex}条的发明人";
                } elseif (empty($knowledgeValue->achievement)) {
                    return "请填写所获知识产权证书第{$showIndex}条的所对应标志性成果";
                } elseif (empty($knowledgeValue->reference_number)) {
                    return "请填写所获知识产权证书第{$showIndex}条的证明材料编号";
                }
            }
        }
        if (empty($formData->scientific)) {
            return '请添加承担科研项目';
        } else {
            $scientificList = $formData->scientific;
            foreach ($scientificList as $scientificKey => $scientificValue) {
                $showIndex = $scientificKey + 1;
                if (empty($scientificValue->project_name)) {
                    return "请填写承担科研项目第{$showIndex}条的项目名称";
                } elseif (empty($scientificValue->expenditure)) {
                    return "请填写承担科研项目第{$showIndex}条的研发经费";
                } elseif (empty($scientificValue->project_origin)) {
                    return "请填写承担科研项目第{$showIndex}条的本人项目来源";
                } elseif (empty($scientificValue->project_number)) {
                    return "请填写承担科研项目第{$showIndex}条的项目编号";
                } elseif (empty($scientificValue->development_date)) {
                    return "请填写承担科研项目第{$showIndex}条的研发起止时间";
                } elseif (empty($scientificValue->status)) {
                    return "请填写承担科研项目第{$showIndex}条的状态";
                } elseif (empty($scientificValue->principal)) {
                    return "请填写承担科研项目第{$showIndex}条的负责人";
                } elseif (empty($scientificValue->sort)) {
                    return "请填写承担科研项目第{$showIndex}条的本人在项目成果中的排序";
                } elseif (empty($scientificValue->reference_number)) {
                    return "请填写承担科研项目第{$showIndex}条的证明材料编号";
                }
            }
        }

        if (empty($formData->engineering)) {
            return '请添加参与重大工程科技项目';
        } else {
            $engineeringList = $formData->engineering;
            foreach ($engineeringList as $engineeringKey => $engineeringValue) {
                $showIndex = $engineeringKey + 1;
                if (empty($engineeringValue->project_name)) {
                    return "请填写参与重大工程科技项目第{$showIndex}条的项目名称";
                } elseif (empty($engineeringValue->issue_company)) {
                    return "请填写参与重大工程科技项目第{$showIndex}条的项目委托单位";
                } elseif (empty($engineeringValue->aboutme)) {
                    return "请填写参与重大工程科技项目第{$showIndex}条的本人参与情况";
                } elseif (empty($engineeringValue->economic)) {
                    return "请填写参与重大工程科技项目第{$showIndex}条的经济效益";
                }
            }
        }

        if (empty($formData->situation)) {
            return '请填写科技成果转化及推广情况';
        }

        if (empty($formData->attachments)) {
            return '请上传附件';
        }
        $attachments = $formData->attachments;
        if (empty($attachments->recommend_letter)) {
            return '请上传附件-推荐函(需加盖推荐单位公章)';
        } else if (empty($attachments->tech_awards)) {
            return '请上传附件-科技奖励和荣誉称号证书或文件';
        } else if (empty($attachments->publications)) {
            return '请上传附件-代表性论文、专著';
        } else if (empty($attachments->ip_certs)) {
            return '请上传附件-所获知识产权证书';
        } else if (empty($attachments->project_files)) {
            return '请上传附件-承担科研项目立项或验收文件';
        } else if (empty($attachments->benefit_certs)) {
            return '请上传附件-效益证明';
        }

        return null;
    }

}
